package library.operation;

import library.ListBook;

import java.util.Scanner;

//查找操作类
public class FindOperation implements IOperation{
    @Override
    public void work(ListBook listBook) {
        System.out.print("请输入你要查找的图书名：");
        Scanner scanner = new Scanner(System.in);
        String name  = scanner.next();
        boolean flag = false;
        for(int i = 0; i < listBook.getSize(); i++){
            //循环遍历查找与输入的图书名相同的图书，然后打印
            if(listBook.getBook(i).getName().equals(name)){
                flag = true;
                System.out.println("[" + i + "] " + listBook.getBook(i));
            }
        }
        if(!flag){
            System.out.println("未找到你要的图书！");
        }
    }
}
